11. 练习:JOIN 问题(第一部分)

练习

你已经了解了 JOIN,我们接下来通过练习让你熟练掌握这一新的知识点。我在下面提供了 ERD 和好几个问题。如果你遇到问题,或想对比检查答案,可以在下一页面找到这些问题的答案!

建议使用以下环境练习你的查询,并将查询保存到文件中。然后将你的文件与下一页面中我的答案进行对比!

问题

  1. 为与 name = Walmart 相关的所有 web_events 创建一个表格。表格应该包含三列: primary_poc 、事件时间和每个事件的 channel (渠道)。此外,你可以选择添加第四列,确保仅选中了 Walmart 事件。

  2. 为每个 sales_rep 对应的 region 以及相关的 accounts 创建一个表格,最终表格应该包含三列:区域名称、销售代表名称,以及客户名称。根据客户名称按字母顺序 (A-Z) 排序。

  3. 提供每个订单的每个 region ,以及 account unit price (total_amt_usd/total)。最终表格应该包含三列:区域名称、客户名称和订单单价。少数几个客户的总订单数为 0,因此我除以的是 (total + 0.01) 以确保不会除以 0。

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: sql-evaluator
  • Opened files (when workspace is loaded): n/a

标出以下所有正确的表述。

SOLUTION:
  • **ON** 语句应该始终让外键等于主键。
  • **JOIN** 语句使我们能够从 **SQL** 数据库中的多个表格里获取数据。
  • 你可以将第一节课学到的所有命令与 **JOIN** 语句一起使用。

选择以下所有表述正确的语句。

SOLUTION:
  • 当我们开始连接多个表格时,别名可以用来缩短表格名称,并且很常用。